//***************************************************************************
//*
//*	File:			dswl_textselection.cpp
//*	Description:	Wrapper for ITextSelection interface
//*
//***************************************************************************

//
//--------------------------------------------------------------- PRECOMPILED
//

#include "stdafx.h"

//
//--------------------------------------------------- DECLARATION DEPENDENCIES
//

//
//--------------------------------------------------------------- DECLARATION
//

#include "../Inc/dswl_textselection.h"

//
//--------------------------------------------------- DEFINITION DEPENDENCIES
//

//
//-------------------------------------------------------------- PREPROCESSOR
//

#ifdef	_DEBUG
#define new DEBUG_NEW
#undef	THIS_FILE
static	char THIS_FILE[] = __FILE__;
#endif

//
//---------------------------------------------------------------- DEFINITION
//

//
//---------------------------------------------------------------------------------------------------
//*************************************     CON/DESTRUCTION     *************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																					  Constructor
//***************************************************************************************************
//**	@DOC		CONSTRUCTION
//**	@MFUNC		Default constructor
//**	@PARM		[in] A pointer to the interface to attach to
//**	@END
//***************************************************************************************************
//inline
CITextSelection::CITextSelection( ITextSelection* a_pITextSelection /*= NULL*/ )
{
	this->m_pITextSelection = a_pITextSelection;
}

//***************************************************************************************************
//**																					   Destructor
//***************************************************************************************************
//**	@DOC		CONSTRUCTION
//**	@MFUNC		Default destructor
//**	@END
//***************************************************************************************************
//inline
CITextSelection::~CITextSelection()
{
	this->m_pITextSelection = NULL;	// explicitly release the interface now
}

//
//---------------------------------------------------------------------------------------------------
//***************************************     PROPERTIES     ****************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																				   GetApplication 
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Determines the application this selection belongs to
//**	@RDESC		A pointer to the application's interface
//**	@END
//***************************************************************************************************
//inline
CIApplication CITextSelection::GetApplication( void ) const 
{
	//
	//	CHECK VALIDITY
	//
	if ( FALSE == this->IsValid() )
	{
		return NULL;
	}

	//
	//	GET DISPATCH INTERFACE
	//
	IDispatch*	pIDispatch = NULL;

	DSWL_VERIFY( this->m_pITextSelection->get_Application( &pIDispatch ) );

	//
	//	QUERY INTERFACE
	//
	CComQIPtr< IApplication, &IID_IApplication > pIApplication ( pIDispatch );	

	//
	//	REPELASE DISPATCH INTERFACE
	//
	DSWL_RELEASE_EX( pIDispatch, CITextDocument::GetApplication );

	//
	//	RETURN QUERIED INTERFACE
	//
	return pIApplication.p;												
}

//***************************************************************************************************
//**																				  GetTextDocument 
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Determines the text document this selection belongs to
//**	@RDESC		A pointer to the text document's interface
//**	@END
//***************************************************************************************************
//inline
CITextDocument CITextSelection::GetTextDocument( void ) const 
{
	//
	//	CHECK VALIDITY
	//
	if ( FALSE == this->IsValid() )
	{
		return NULL;
	}

	//
	//	GET DISPATCH INTERFACE
	//
	IDispatch*	pIDispatch = NULL;

	DSWL_VERIFY( this->m_pITextSelection->get_Parent( &pIDispatch ) );

	//
	//	QUERY INTERFACE
	//
	CComQIPtr< ITextDocument, &IID_ITextDocument > pITextDocument ( pIDispatch );	

	//
	//	REPELASE DISPATCH INTERFACE
	//
	DSWL_RELEASE_EX( pIDispatch, CITextDocument::GetTextDocument );

	//
	//	RETURN QUERIED INTERFACE
	//
	return pITextDocument.p;												
}

//***************************************************************************************************
//**																						  GetText
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Determines the selection's text
//**	@RDESC		The selected text
//**	@COMM		An invalid selection (e.g. <t NULL>) returns an empty string.
//**	@END
//***************************************************************************************************
//inline
CString CITextSelection::GetText( void ) const 
{
	//
	//	CHECK VALIDITY
	//
	if ( TRUE == this->IsNull() )
	{
		return _T( "" );
	}

	//
	//	DELEGATE
	//
	CComBSTR bszText( _T( "" ) );
	
	DSWL_VERIFY( this->m_pITextSelection->get_Text( &bszText ) );
	
	return bszText;
}

//***************************************************************************************************
//**																				   GetCurrentLine	  
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Determines the current line's index
//**	@RDESC		The current line's index
//**	@END
//***************************************************************************************************
//inline
long CITextSelection::GetCurrentLine( void ) const 
{
	ASSERT( TRUE == this->IsValid() );

	long lCurrentLine = 0;

	DSWL_VERIFY( this->m_pITextSelection->get_CurrentLine( &lCurrentLine ) );
	
	return lCurrentLine;
}

//***************************************************************************************************
//**																				 GetCurrentColumn 
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Determines the current column's index
//**	@RDESC		The current column's index
//**	@END
//***************************************************************************************************
//inline
long CITextSelection::GetCurrentColumn( void ) const 
{
	ASSERT( TRUE == this->IsValid() );

	long lCurrentColumn = 0;

	DSWL_VERIFY( this->m_pITextSelection->get_CurrentColumn( &lCurrentColumn ) );
	
	return lCurrentColumn;
}

//***************************************************************************************************
//**																					GetBottomLine
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Determines the bottom line's index
//**	@RDESC		The bottom line's index
//**	@END
//***************************************************************************************************
//inline
long CITextSelection::GetBottomLine( void ) const 
{
	ASSERT( TRUE == this->IsValid() );

	long lBottomLine = 0;

	DSWL_VERIFY( this->m_pITextSelection->get_BottomLine( &lBottomLine ) );
	
	return lBottomLine;
}

//***************************************************************************************************
//**																					   GetTopLine
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Determines the top line's index
//**	@RDESC		The top line's index
//**	@END
//***************************************************************************************************
//inline
long CITextSelection::GetTopLine( void ) const 
{
	ASSERT( TRUE == this->IsValid() );

	long lTopLine = 0;

	DSWL_VERIFY( this->m_pITextSelection->get_TopLine( &lTopLine ) );
	
	return lTopLine;
}
 
//***************************************************************************************************
//**																						  SetText
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Replaces the selection's text
//**	@PARM		[in] The text to paste
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::SetText( const CString& a_strText ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComBSTR bszText( a_strText );
	
	DSWL_VERIFY( this->m_pITextSelection->put_Text( bszText ) );
}

//
//---------------------------------------------------------------------------------------------------
//***************************************     INFORMATION     ***************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																						   IsNull
//***************************************************************************************************
//**	@DOC		INFORMATION
//**	@MFUNC		Determines whether the internal pointer is <t NULL>
//**	@RDESC		<t TRUE> if the internal pointer is <t NULL>, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CITextSelection::IsNull( void ) const
{
	return ( NULL == this->m_pITextSelection.p );
}

//***************************************************************************************************
//**																						  IsValid
//***************************************************************************************************
//**	@DOC		INFORMATION
//**	@MFUNC		Determines whether the internal pointer differs from <t NULL>
//**	@RDESC		<t TRUE> if the internal pointer differs from <t NULL>, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CITextSelection::IsValid( void ) const
{
	return ( NULL != this->m_pITextSelection.p );
}

//***************************************************************************************************
//**																						  IsEmpty
//***************************************************************************************************
//**	@DOC		INFORMATION
//**	@MFUNC		Determines whether the selection is empty
//**	@RDESC		<t TRUE> if the selection is empty, <t FALSE> otherwise.
//**	@DEVNOTE	This method may safely be called for invalid interfaces
//**	@END
//***************************************************************************************************
//inline
BOOL CITextSelection::IsEmpty( void ) const
{
	//
	//	CHECK VALIDITY
	//
	if ( TRUE == this->IsNull() )
	{
		return TRUE;				// consider invalid selections as empty
	}

	//
	//	CHECK TEXT
	//
	return this->GetText().IsEmpty();
}

//
//---------------------------------------------------------------------------------------------------
//**************************************     MODIFICATION     ***************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																					  SetBookmark
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Bookmarks the current line
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::SetBookmark( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->SetBookmark() );
}

//***************************************************************************************************
//**																					ClearBookmark	   
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Clears the boomark at the current line
//**	@RDESC		<t TRUE> if successful, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CITextSelection::ClearBookmark( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	VARIANT_BOOL varResult( FALSE );

	DSWL_VERIFY( this->m_pITextSelection->ClearBookmark( &varResult ) );

	return varResult;
}

//***************************************************************************************************
//**																					 NextBookmark
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Jumps to the next bookmark
//**	@RDESC		<t TRUE> if successful, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CITextSelection::NextBookmark( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	VARIANT_BOOL varResult( FALSE );

	DSWL_VERIFY( this->m_pITextSelection->NextBookmark( &varResult ) );

	return varResult;
}

//***************************************************************************************************
//**																				 PreviousBookmark	   
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Jumps to the previous bookmark
//**	@RDESC		<t TRUE> if successful, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CITextSelection::PreviousBookmark( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	VARIANT_BOOL varResult( FALSE );

	DSWL_VERIFY( this->m_pITextSelection->PreviousBookmark( &varResult ) );

	return varResult;
}

//***************************************************************************************************
//**																						   Cancel
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Cancels the current selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::Cancel( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->Cancel() );
}

//***************************************************************************************************
//**																					   SelectLine
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Selects the current line
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::SelectLine( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->SelectLine() );
}

//***************************************************************************************************
//**																					    SelectAll
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Selects the whole document
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::SelectAll( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->SelectAll() );
}

//***************************************************************************************************
//**																						   MoveTo
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor to the specified line and column while eventually extending the 
//**				selection
//**	@PARM		[in] The line index
//**	@PARM		[in] The column index
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::MoveTo( long a_lLine, long a_lColumn, BOOL a_bExtend ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend( a_bExtend );

	DSWL_VERIFY( this->m_pITextSelection->MoveTo( a_lLine, a_lColumn, varExtend ) );
}

//***************************************************************************************************
//**																					     GoToLine
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor to the specified line while eventually extending the selection
//**	@PARM		[in] The line index
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::GoToLine( long a_lLine, BOOL a_bExtend ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend( a_bExtend );

	DSWL_VERIFY( this->m_pITextSelection->GoToLine( a_lLine, varExtend ) );
}

//***************************************************************************************************
//**																						 CharLeft
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor the specified number of chars to the left while eventually 
//**				extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@PARM		[in] The number of repetitions
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::CharLeft( BOOL a_bExtend, long a_lCount ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend	( a_bExtend );
	CComVariant varCount	( a_lCount	);

	DSWL_VERIFY( this->m_pITextSelection->CharLeft( varExtend, varCount ) );
}

//***************************************************************************************************
//**																					    CharRight
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor the specified number of chars to the right while eventually 
//**				extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@PARM		[in] The number of repetitions
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::CharRight( BOOL a_bExtend, long a_lCount ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend	( a_bExtend );
	CComVariant varCount	( a_lCount	);

	DSWL_VERIFY( this->m_pITextSelection->CharRight( varExtend, varCount ) );
}

//***************************************************************************************************
//**																					     WordLeft
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor the specified number of words to the left while eventually 
//**				extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@PARM		[in] The number of repetitions
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::WordLeft( BOOL a_bExtend, long a_lCount ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend	( a_bExtend );
	CComVariant varCount	( a_lCount	);

	DSWL_VERIFY( this->m_pITextSelection->WordLeft( varExtend, varCount ) );
}

//***************************************************************************************************
//**																					    WordRight
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor the specified number of words to the right while eventually 
//**				extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@PARM		[in] The number of repetitions
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::WordRight( BOOL a_bExtend, long a_lCount ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend	( a_bExtend );
	CComVariant varCount	( a_lCount	);

	DSWL_VERIFY( this->m_pITextSelection->WordRight( varExtend, varCount ) );
}

//***************************************************************************************************
//**																						   LineUp
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor the specified number of lines upwards while eventually 
//**				extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@PARM		[in] The number of repetitions
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::LineUp( BOOL a_bExtend, long a_lCount ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend	( a_bExtend );
	CComVariant varCount	( a_lCount	);

	DSWL_VERIFY( this->m_pITextSelection->LineUp( varExtend, varCount ) );
}

//***************************************************************************************************
//**																						 LineDown 
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor the specified number of lines downwards while eventually 
//**				extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@PARM		[in] The number of repetitions
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::LineDown( BOOL a_bExtend, long a_lCount ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend	( a_bExtend );
	CComVariant varCount	( a_lCount	);

	DSWL_VERIFY( this->m_pITextSelection->LineDown( varExtend, varCount ) );
}

//***************************************************************************************************
//**																						   PageUp
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor the specified number of pages upwards while eventually 
//**				extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@PARM		[in] The number of repetitions
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::PageUp( BOOL a_bExtend, long a_lCount ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend	( a_bExtend );
	CComVariant varCount	( a_lCount	);

	DSWL_VERIFY( this->m_pITextSelection->PageUp( varExtend, varCount ) );
}

//***************************************************************************************************
//**																					     PageDown
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor the specified number of pages downwards while eventually 
//**				extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@PARM		[in] The number of repetitions
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::PageDown( BOOL a_bExtend, long a_lCount ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend	( a_bExtend );
	CComVariant varCount	( a_lCount	);

	DSWL_VERIFY( this->m_pITextSelection->PageDown( varExtend, varCount ) );
}

//***************************************************************************************************
//**																					  StartOfLine  
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor to the end of the line while eventually extending the selection
//**	@PARM		[in] The options
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::StartOfLine( DsStartOfLineOptions a_enuOptions, BOOL a_bExtend ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend	( a_bExtend		);
	CComVariant varOptions	( a_enuOptions	);

	DSWL_VERIFY( this->m_pITextSelection->StartOfLine( varOptions, varExtend ) );
}

//***************************************************************************************************
//**																						EndOfLine	   
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor to the end of the line while eventually extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::EndOfLine( BOOL a_bExtend ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend( a_bExtend );

	DSWL_VERIFY( this->m_pITextSelection->EndOfLine( varExtend ) );
}

//***************************************************************************************************
//**																				  StartOfDocument	   
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor to the top of the document while eventually extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::StartOfDocument( BOOL a_bExtend ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend( a_bExtend );

	DSWL_VERIFY( this->m_pITextSelection->StartOfDocument( varExtend ) );
}

//***************************************************************************************************
//**																					EndOfDocument
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Moves the cursor to the end of the document while eventually extending the selection
//**	@PARM		[in] A flag indicating whether to extend the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::EndOfDocument( BOOL a_bExtend ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varExtend( a_bExtend );

	DSWL_VERIFY( this->m_pITextSelection->EndOfDocument( varExtend ) );
}

//***************************************************************************************************
//**																						  NewLine	   
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Inserts a new line at the current position
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::NewLine( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varReserved( 0 );

	DSWL_VERIFY( this->m_pITextSelection->NewLine( varReserved ) );
}

//***************************************************************************************************
//**																				DestructiveInsert				   
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Inserts the specified text at the current position in overwrite mode
//**	@PARM		[in] The text to insert
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::DestructiveInsert( const CString& a_strText ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComBSTR bszText( a_strText );

	DSWL_VERIFY( this->m_pITextSelection->DestructiveInsert( bszText ) );
}

//***************************************************************************************************
//**																					    Backspace
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Simulates pressing the <BACKSPACE> key the specified number of times
//**	@PARM		[in] The number of repetitions
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::Backspace( long a_lCount ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varCount( a_lCount );

	DSWL_VERIFY( this->m_pITextSelection->Backspace( varCount ) );
}

//***************************************************************************************************
//**																						   Delete 
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Simulates pressing the <DEL> key the specified number of times
//**	@PARM		[in] The number of repetitions
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::Delete( long a_lCount ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varCount( a_lCount );

	DSWL_VERIFY( this->m_pITextSelection->Delete( varCount ) );
}

//***************************************************************************************************
//**																				 DeleteWhitespace 
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Deletes all whitespaces in the specified direction
//**	@PARM		[in] The options
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::DeleteWhitespace( DsWhitespaceOptions a_enuDir ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varDir( a_enuDir );

	DSWL_VERIFY( this->m_pITextSelection->DeleteWhitespace( varDir ) );
}

//***************************************************************************************************
//**																							 Copy
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Copies the selection to the clipboard
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::Copy( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->Copy() );
}

//***************************************************************************************************
//**																							  Cut
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Copies the selection to the clipboard and deletes it
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::Cut( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->Cut() );
}

//***************************************************************************************************
//**																							Paste
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Pastes the clipboard content at the current position
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::Paste( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->Paste() );
}

//***************************************************************************************************
//**																					   ChangeCase
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Changes the selection's case
//**	@PARM		[in] The options
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::ChangeCase( DsCaseOptions a_enuType ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->ChangeCase( a_enuType ) );
}

//***************************************************************************************************
//**																						   Tabify
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Tabifies the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::Tabify( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->Tabify() );
}

//***************************************************************************************************
//**																					     Untabify
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Un-Tabifies the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::Untabify( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->Untabify() );
}

//***************************************************************************************************
//**																						   Indent
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Indents the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::Indent( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varReserved( 0 );

	DSWL_VERIFY( this->m_pITextSelection->Indent( varReserved ) );
}

//***************************************************************************************************
//**																					     Unindent
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Un-Indents the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::Unindent( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComVariant varReserved( 0 );

	DSWL_VERIFY( this->m_pITextSelection->Unindent( varReserved ) );
}

//***************************************************************************************************
//**																					  SmartFormat  
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Smart-Formats the selection
//**	@END
//***************************************************************************************************
//inline
void CITextSelection::SmartFormat( void ) 
{
	ASSERT( TRUE == this->IsValid() );

	DSWL_VERIFY( this->m_pITextSelection->SmartFormat() );
}

//***************************************************************************************************
//**																						 FindText   
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Finds (and marks) the next occurance of the specified text
//**	@PARM		[in] The text to find
//**	@PARM		[in] The options (a combination of <t DsTextSearchOptions> flags)
//**	@RDESC		<t TRUE> if successful, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CITextSelection::FindText( const CString& a_strFind, DWORD a_dwFlags ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComBSTR		bszFind		(						a_strFind	);
	CComVariant		varFlags	( static_cast< long > (	a_dwFlags )	);
	VARIANT_BOOL	varResult	(						FALSE		);

	#ifdef FindText
	#undef FindText
	#endif

	DSWL_VERIFY( this->m_pITextSelection->FindText( bszFind, varFlags, &varResult ) );

	return varResult;
}

//***************************************************************************************************
//**																					  ReplaceText	   
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Replaces all occurances of the specified text with the specified replace string
//**	@PARM		[in] The text to find
//**	@PARM		[in] The text to replace with
//**	@PARM		[in] The options (a combination of <t DsTextSearchOptions> flags)
//**	@RDESC		<t TRUE> if successful, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CITextSelection::ReplaceText( const CString& a_strFind, const CString& a_strReplace, DWORD a_dwFlags ) 
{
	ASSERT( TRUE == this->IsValid() );

	CComBSTR		bszFind		(						a_strFind		);
	CComBSTR		bszReplace	(						a_strReplace	);
	CComVariant		varFlags	( static_cast< long > (	a_dwFlags )		);
	VARIANT_BOOL	varResult	(						FALSE			);

	#ifdef ReplaceText
	#undef ReplaceText
	#endif

	DSWL_VERIFY( this->m_pITextSelection->ReplaceText( bszFind, bszReplace, varFlags, &varResult ) );

	return varResult;
}

//
//---------------------------------------------------------------------------------------------------
//****************************************     OPERATORS     ****************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																					  operator ==
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text selection to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CITextSelection::operator == ( const CITextSelection& a_Other ) const 
{
	return this->m_pITextSelection == a_Other.m_pITextSelection;
}

//***************************************************************************************************
//**																					  operator !=
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text selection to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CITextSelection::operator != ( const CITextSelection& a_Other ) const 
{
	return this->m_pITextSelection != a_Other.m_pITextSelection;
}

//***************************************************************************************************
//**																					  operator <=
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text selection to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CITextSelection::operator <= ( const CITextSelection& a_Other ) const 
{
	return this->m_pITextSelection.p <= a_Other.m_pITextSelection.p;
}

//***************************************************************************************************
//**																					  operator >=
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text selection to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CITextSelection::operator >= ( const CITextSelection& a_Other ) const 
{
	return this->m_pITextSelection.p >= a_Other.m_pITextSelection.p;
}

//***************************************************************************************************
//**																					   operator <
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text selection to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CITextSelection::operator < ( const CITextSelection& a_Other ) const 
{
	return this->m_pITextSelection.p < a_Other.m_pITextSelection.p;
}

//***************************************************************************************************
//**																					   operator >
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The text selection to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CITextSelection::operator > ( const CITextSelection& a_Other ) const 
{
	return this->m_pITextSelection.p > a_Other.m_pITextSelection.p;
}

//***************************************************************************************************
//**																					   operator =
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Copy operator
//**	@PARM		[in] The text selection to attach to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CITextSelection& CITextSelection::operator = ( ITextSelection* a_pIOther ) 
{
	this->m_pITextSelection = a_pIOther;

	return (*this);
}

//***************************************************************************************************
//**																					   operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Dereference operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
ITextSelection* CITextSelection::operator * ( void ) 
{
	return this->m_pITextSelection.p;
}

//***************************************************************************************************
//**																				 const operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Dereference operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
const ITextSelection* CITextSelection::operator * ( void ) const 
{
	return this->m_pITextSelection.p;
}

//***************************************************************************************************
//**																					  operator ->
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Member access operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
ITextSelection* CITextSelection::operator -> ( void ) 
{
	return * (*this);
}

//***************************************************************************************************
//**																				const operator ->
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Member access operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
const ITextSelection* CITextSelection::operator -> ( void ) const 
{
	return * (*this);
}

//---------------------------------------------------------------------------------------------------
//***************************************************************************************************
//---------------------------------------------------------------------------------------------------

#ifdef _DSWL_SWITCH_USE_AUTOCAST
#ifdef _DSWL_SWITCH_USE_UNSAFE_AUTOCAST

//***************************************************************************************************
//**																				 const operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		TypeCast operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CITextSelection::operator ITextSelection* ( void ) const 
{
	return this->m_pITextSelection.p;
}

#else

//***************************************************************************************************
//**																					   operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		TypeCast operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CITextSelection::operator ITextSelection* ( void ) 
{
	return this->m_pITextSelection.p;
}

//***************************************************************************************************
//**																				 const operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		TypeCast operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CITextSelection::operator const ITextSelection* ( void ) const 
{
	return this->m_pITextSelection.p;
}

#endif
#endif
